//
//  LoginViewController.m
//  OurRelaxDemo
//
//  Created by 王雅蓉 on 15/7/7.
//  Copyright (c) 2015年 于宾尧. All rights reserved.
//

#import "LoginViewController.h"

@interface LoginViewController ()<UIScrollViewDelegate>

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.view addSubview:self.scrollView];
    self.scrollView.delegate = self;
    self.scrollView.backgroundColor = [UIColor yellowColor];
    self.scrollView.contentSize = CGSizeMake([[UIScreen mainScreen]bounds].size.width * 4, 0);
    
    
    
    [self.scrollView release];
    
    for (int i = 0; i < 4; i++) {
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake([[UIScreen mainScreen]bounds].size.width * i, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height)];
        NSString *name = [NSString stringWithFormat:@"image%d",i+1];
        NSString *filePath = [[NSBundle mainBundle] pathForResource:name ofType:@"png"];
        self.imageView.image = [UIImage imageWithContentsOfFile:filePath];
        
        [self.scrollView addSubview:self.imageView];
        
    }
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    
    self.pageC = [[UIPageControl alloc] init];
    self.pageC.backgroundColor = [UIColor clearColor];
    self.pageC.numberOfPages = 4;
    self.pageC.currentPage = 0;
    self.pageC.tag = 10001;
    self.pageC.currentPageIndicatorTintColor = [UIColor blackColor];
    self.pageC.pageIndicatorTintColor = [UIColor lightGrayColor];
    
    self.pageC.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width / 2.0 - 40, [[UIScreen mainScreen] bounds].size.height - 60, 80, 40);
    
    [self.pageC addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:self.pageC];
    
    [self.pageC release];
    
}

-(void)pageAction:(UIPageControl *)page
{
    
    [self.scrollView setContentOffset:CGPointMake([[UIScreen mainScreen]bounds].size.width * page.currentPage, 0) animated:YES];
    
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    
    UIPageControl *tmp = (UIPageControl *)[self.view viewWithTag:10001];
    tmp.currentPage = scrollView.contentOffset.x/[[UIScreen mainScreen]bounds].size.width;
    if (self.scrollView.contentOffset.x / [[UIScreen mainScreen]bounds].size.width == 3 ) {
        
        UIButton *button = [[UIButton alloc]init];
        button.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width / 2.0 - 60, [[UIScreen mainScreen] bounds].size.height - 100, 120, 40);
        
        [button setTintColor:[UIColor whiteColor]];;
        [button setTitle:@"点击体验" forState:UIControlStateNormal];
        button.backgroundColor = [UIColor clearColor];
        button.layer.cornerRadius = 6;
        [button.layer setBorderWidth:2];
        [button.layer setBorderColor:[[UIColor whiteColor] CGColor]];
        [self.view addSubview:button];
        
        [button addTarget:self  action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    }
}


-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return [scrollView.subviews objectAtIndex:0];
}


-(void)buttonAction{
    
    [self.myDelegate change];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
